<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
      * 翻转数组
      * @param arr 原始数组，需要被翻转的数组
      * @returns newArr 翻转后的数组
      */
        const arr = [10, 20, 30, 40, 50]; // 原始数组
        const newArr = []; // 翻转后的数组
        // 使用循环遍历原始数组，将元素以相反的顺序放入新数组中
        for (let i = 0; i < arr.length; i++) {
            newArr[i] = arr[arr.length - i - 1];
        }
        console.log(JSON.stringify(newArr));

        const arr2 = [20, 10, 50, 30, 40];
        for (let i = 0; i < arr2.length; i++) {
            for (let j = 0; j < arr2.length - i - 1; j++) {
                if (arr2[j] > arr2[j + 1]) {
                    let temp = arr2[j];
                    arr2[j] = arr2[j + 1];
                    arr2[j + 1] = temp;
                }
            }
        }
        console.log('arr2--', JSON.stringify(arr2));

        //数组从小到大排序
        const arr3 = [5, 8, 11, 20, 4, 9, 15]
        let result = arr3.sort((a, b) => a - b);
        console.log('arr3=' + JSON.stringify(arr3));
        console.log('result=' + JSON.stringify(result));
    </script>
</body>

</html>